﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanlyDanhsachThiCapPhong
{
    public partial class frmDatThongSoKiThi : Form
    {
        private string fixDir = "C:\\Database\\Data.dat";
        public frmDatThongSoKiThi()
        {
            InitializeComponent();
        }

        private void btThemHoiDong_Click(object sender, EventArgs e)
        {
            frmThemHoiDongThi hdt = new frmThemHoiDongThi();
            hdt.FormClosed += new FormClosedEventHandler(child_FormClosed);
            hdt.Show();
        }

        private void btOk_Click(object sender, EventArgs e)
        {
            Truong truong = new Truong();
            truong.ThemHoiDong(cbHoiDong.Text,cbTruong.Text);
            dgvHoiDongThi.DataSource = truong.ListTruong();
        }

        private void frmDatThongSoKiThi_Load(object sender, EventArgs e)
        {
            loadMain();
        }

        private void btCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        void child_FormClosed(object sender, FormClosedEventArgs e)
        {
            //when child form is closed, this code is executed
            HocSinh hoc = new HocSinh();
            hoc.Directory = fixDir;
            try
            {
                cbHoiDong.Items.Clear();
                cbTruong.Items.Clear();
                loadMain();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        void loadMain()
        {
            HoiDongThi hdt = new HoiDongThi();
            Truong truong = new Truong();

            foreach (string name in hdt.danhsachHoiDong())
            {
                cbHoiDong.Items.Add(name);
            }
            cbHoiDong.SelectedIndex = 0;
            foreach (string name in truong.danhsachTruong())
            {
                cbTruong.Items.Add(name);
            }

            cbTruong.SelectedIndex = 0;
            dgvHoiDongThi.DataSource = truong.ListTruong();
        }
    }
}
